home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / dev / c / EasygadgetsSou.lha / EasyGadgets / Task.c < prev    next >
C/C++ Source or Header  |  1995-11-28  |  10KB  |  402 lines

  1. /*
  2.  *    File:                    Task.c
  3.  *    Description:    
  4.  *
  5.  *    (C) 1994,1995 Ketil Hunn
  6.  *
  7.  */
  8.  
  9. #ifndef    EG_TASK_C
  10. #define    EG_TASK_C
  11.  
  12. /*** PRIVATE INCLUDES ****************************************************************/
  13. #include <intuition/intuition.h>
  14.  
  15. /*** DEFINES *************************************************************************/
  16. #define    EG_EGWINDOW                ~0
  17. #define IM(o) ((struct Image *)o)
  18.  
  19. /*** FUNCTIONS ***********************************************************************/
  20.  
  21. __asm __saveds BYTE egOpenTaskA(register __a1 struct egTask                *task,
  22.                                                                 register __a0 struct TagItem            *taglist)
  23. {
  24.     struct TagItem    *tstate=taglist;
  25.     register struct TagItem    *tag;
  26.     register BYTE success=FALSE,zoom=FALSE, depth=FALSE, iconify=FALSE, helpmenu=FALSE, lendmenu=FALSE;
  27.     register ULONG idcmp=0L;
  28.     struct Menu        *menu=NULL;
  29.     UWORD                    minwidth=0, minheight=0;
  30.  
  31.     if(task->openguifunc)
  32.         egCallHook(task->openguifunc, task->eg_UserData);
  33.  
  34.     if(egTaskToFront(task))
  35.         return FALSE;
  36.  
  37.     task->screen=NULL;
  38.     if(    NULL==(task->screen=(struct Screen *)GetTagData(WA_CustomScreen,    NULL, taglist)) ||
  39.             NULL==(task->screen=(struct Screen *)GetTagData(WA_PubScreen,            NULL, taglist)))
  40.         ;
  41.     if(task->screen==NULL)
  42.         task->screen=task->eg->screen;
  43.  
  44.     task->eg->ng.ng_TextAttr=task->eg->screen->Font;
  45.  
  46.     if(task->eg->dri=task->dri=GetScreenDrawInfo(task->screen))
  47.         if(task->eg->ng.ng_VisualInfo=task->VisualInfo=GetVisualInfo(task->screen, NULL))
  48.         {
  49.             while(tag=NextTagItem(&tstate))
  50.                 switch(tag->ti_Tag)
  51.                 {
  52.                     case WA_Left:
  53.                         task->coords.LeftEdge=(WORD)tag->ti_Data;
  54.                         break;
  55.                     case WA_Top:
  56.                         task->coords.TopEdge=(WORD)tag->ti_Data;
  57.                         break;
  58.                     case WA_Width:
  59.                         task->coords.Width=(WORD)tag->ti_Data;
  60.                         break;
  61.                     case WA_Height:
  62.                         task->coords.Height=(WORD)tag->ti_Data;
  63.                         break;
  64.                     case EG_InitialCentre:
  65.                         if(ISBITSET(task->flags, TASK_NOSIZE))
  66.                         {
  67.                             task->coords.LeftEdge    =(task->screen->Width-task->coords.Width)/2;
  68.                             task->coords.TopEdge    =(task->screen->Height-task->coords.Height)/2;
  69.                         }
  70.                         break;
  71.                     case EG_InitialUpperLeft:
  72.                         if(ISBITSET(task->flags, TASK_NOSIZE))
  73.                         {
  74.                             task->coords.LeftEdge    =0;
  75.                             task->coords.TopEdge    =task->eg->ScreenBarHeight;
  76.                         }
  77.                         break;
  78.                     case EG_IDCMP:
  79.                         idcmp    =    (ULONG)(tag->ti_Data);
  80.                         idcmp|=    IDCMP_REFRESHWINDOW     |    IDCMP_SIZEVERIFY    |    IDCMP_NEWSIZE            |    
  81.                                         IDCMP_CLOSEWINDOW            |    IDCMP_MENUHELP        |    IDCMP_RAWKEY            |    
  82.                                         IDCMP_CHANGEWINDOW        | IDCMP_INACTIVEWINDOW;
  83.                         break;
  84.                     case WA_MinWidth:
  85.                         minwidth=(UWORD)tag->ti_Data;
  86.                         zoom=TRUE;
  87.                         break;
  88.                     case WA_MinHeight:
  89.                         minheight=(UWORD)tag->ti_Data;
  90.                         zoom=TRUE;
  91.                         break;
  92.                     case EG_LendMenu:
  93.                         lendmenu=TRUE;
  94.                     case EG_Menu:
  95.                         menu=(struct Menu *)tag->ti_Data;
  96.                         break;
  97.                     case EG_HelpMenu:
  98.                         helpmenu=(BYTE)tag->ti_Data;
  99.                         break;
  100.                     case EG_RefreshFunc:
  101.                         task->refreshfunc=(void *)tag->ti_Data;
  102.                         break;
  103.                     case EG_RenderFunc:
  104.                         task->renderfunc=(void *)tag->ti_Data;
  105.                         break;
  106.                     case EG_OpenFunc:
  107.                         task->openfunc=(void *)tag->ti_Data;
  108.                         break;
  109.                     case EG_CloseFunc:
  110.                         task->closefunc=(void *)tag->ti_Data;
  111.                         break;
  112.                     case EG_HandleFunc:
  113.                         task->handlefunc=(void *)tag->ti_Data;
  114.                         break;
  115.                     case WA_DepthGadget:
  116.                         depth=(BYTE)tag->ti_Data;
  117.                         break;
  118.                     case WA_SizeGadget:
  119.                         zoom=(BYTE)tag->ti_Data;
  120.                         break;
  121.                     case EG_IconifyGadget:
  122.                         iconify=(BYTE)tag->ti_Data;
  123.                         idcmp|=GADGETUP;
  124.                         break;
  125.                     case EG_GhostWhenBlocked:
  126.                         IFTRUESETBIT(tag->ti_Data, task->flags, TASK_GHOSTWHENBLOCKED);
  127.                         break;
  128.                     case EG_Blocked:
  129.                         IFTRUESETBIT(tag->ti_Data, task->flags, TASK_BLOCKED);
  130.                         break;
  131.                     case EG_HelpNode:
  132.                         task->eg->lasthelpnode=task->helpnode=(UBYTE *)tag->ti_Data;
  133.                         break;
  134.                     case EG_OpenGUIFunc:
  135.                         task->openguifunc=(void *)tag->ti_Data;
  136.                         break;
  137.                     case EG_CloseGUIFunc:
  138.                         task->closeguifunc=(void *)tag->ti_Data;
  139.                         break;
  140.                     case EG_ScreenNotify:
  141.                         if(task->eg->notifyport && tag->ti_Data)
  142.                             task->screenhandle=AddCloseScreenClient((struct Screen *)tag->ti_Data,
  143.                                                                                                             task->eg->notifyport,
  144.                                                                                                             0);
  145.                         break;
  146.                     case EG_PubScreenNotify:
  147.                         if(task->eg->notifyport && tag->ti_Data)
  148.                             task->screenhandle=AddPubScreenClient(task->eg->notifyport, 0);
  149.                         break;
  150.                 }
  151.  
  152.             if(iconify && task->eg->iconifyclass)
  153.             {
  154.                 register WORD        relpos=0;
  155.                 register int        resolution=(task->eg->screen->Flags & SCREENHIRES ? SYSISIZE_MEDRES : SYSISIZE_LOWRES);
  156.                 register Object    *depthimage, *zoomimage;
  157.                 
  158.                 if(depthimage=NewObject(NULL, SYSICLASS,
  159.                                                                 SYSIA_DrawInfo, task->eg->dri,
  160.                                                                 SYSIA_Which,        DEPTHIMAGE,
  161.                                                                 SYSIA_Size,            resolution,
  162.                                                                 TAG_DONE))
  163.                 {
  164.                     if(zoomimage=NewObject(    NULL, SYSICLASS,
  165.                                                                     SYSIA_DrawInfo, task->eg->dri,
  166.                                                                     SYSIA_Which,        ZOOMIMAGE,
  167.                                                                     SYSIA_Size,            resolution,
  168.                                                                     TAG_DONE))
  169.                     {
  170.                         if(depth)
  171.                             relpos=-IM(depthimage)->Width+1;
  172.                         if(zoom)
  173.                             relpos-=IM(zoomimage)->Width-1;
  174.                         if(iconify)
  175.                             relpos-=IM(depthimage)->Width-1;
  176.     
  177.                         task->iconifygadget=(struct Gadget *)NewObject(task->eg->iconifyclass,    NULL,
  178.                                                                         GA_TopBorder,        TRUE,
  179.                                                                         GA_RelRight,        relpos,
  180.                                                                         GA_Width,                IM(zoomimage)->Width,
  181.                                                                         GA_Height,            task->screen->BarHeight,
  182.                                                                         GA_RelVerify,        TRUE,
  183.                                                                         TAG_DONE);
  184.  
  185.                         DisposeObject(zoomimage);
  186.                     }
  187.                     DisposeObject(depthimage);
  188.                 }
  189.             }
  190.  
  191.             if(task->window=OpenWindowTags(NULL,
  192.                                                                 WA_Left,                    task->coords.LeftEdge,
  193.                                                                 WA_Top,                        task->coords.TopEdge,
  194.                                                                 WA_Width,                    MAX(minwidth, task->coords.Width),
  195.                                                                 WA_Height,                MAX(minheight, task->coords.Height),
  196.                                                                 WA_NewLookMenus,    TRUE,
  197.                                                                 WA_MenuHelp,            TRUE,
  198.                                                                 TAG_MORE,                    taglist,
  199.                                                                 TAG_DONE))
  200.             {
  201.                 if(iconify && task->iconifygadget)
  202.                 {
  203.                     AddGadget(task->window, task->iconifygadget, 0);
  204.                     RefreshGList(task->iconifygadget, task->window, NULL, 1);
  205.                 }
  206.  
  207.                 if(idcmp)
  208.                 {
  209.                     task->window->UserPort=task->eg->msgport;
  210.                     ModifyIDCMP(task->window,    idcmp);
  211.                 }
  212.  
  213.                 if(task->renderfunc)
  214.                 {
  215.                     egCallHook(task->renderfunc, task->eg_UserData);
  216.                     egRenderGadgets(task);
  217.                 }
  218.                 if(task->refreshfunc)
  219.                     egCallHook(task->refreshfunc, task->eg_UserData);
  220.  
  221.                 task->status=STATUS_OPEN;
  222.                 if(ISBITSET(task->flags, TASK_BLOCKED))
  223.                     egLockTaskA(task, NULL);
  224.  
  225.                 if(menu)
  226.                 {
  227.                     if(!lendmenu)
  228.                     {
  229.                         LayoutMenus(menu, task->VisualInfo,
  230.                                                             GTMN_NewLookMenus,    TRUE,
  231.                                                             TAG_END);
  232.                         if(helpmenu)
  233.                             egMakeHelpMenu(menu, task->screen);
  234.                     }
  235.                     SetMenuStrip(task->window, menu);
  236.                 }
  237.  
  238.                 task->window->UserData=(APTR)EG_EGWINDOW;
  239.                 CLEARBIT(task->flags, TASK_NOSIZE);
  240.                 success=TRUE;
  241.             }
  242.         }
  243.     return success;
  244. }
  245.  
  246. __asm __saveds void egCloseTask(register __a0 struct egTask *task)
  247. {
  248.     register struct Window *window=task->window;
  249.     register ULONG close=TRUE;
  250.  
  251. #ifdef MYDEBUG_H
  252.     DebugOut("egCloseTask");
  253. #endif
  254.  
  255.     if(window)
  256.     {
  257. #ifdef MYDEBUG_H
  258.     DebugOut("freed glist");
  259. #endif
  260.  
  261.         if(task->screenhandle)
  262.         {
  263.             while(!RemPubScreenClient(task->screenhandle))
  264.                 Delay(10);
  265.             task->screenhandle=NULL;
  266.         }
  267.         if(task->pubhandle)
  268.         {
  269.             while(!RemPubScreenClient(task->pubhandle))
  270.                 Delay(10);
  271.             task->pubhandle=NULL;
  272.         }
  273.  
  274.         if(task->closefunc)
  275.             close=egCallHook(task->closefunc, (APTR)task->window);
  276.  
  277.         if(close)
  278.         {
  279.             egFreeGList(task);
  280.  
  281.             if(ISBITSET(task->flags, TASK_BLOCKED))
  282.             {
  283.                 egUnlockTaskA(task, NULL);
  284.                 SETBIT(task->flags, TASK_BLOCKED);
  285.             }
  286.  
  287.             ClearMenuStrip(window);
  288.             task->coords.LeftEdge    =window->LeftEdge;
  289.             task->coords.TopEdge    =window->TopEdge;
  290.             task->coords.Width        =window->Width;
  291.             task->coords.Height        =window->Height;
  292.             egCloseWindowSafely(window);
  293. #ifdef MYDEBUG_H
  294.             DebugOut("closed window safely");
  295. #endif
  296.             if(task->iconifygadget)
  297.             {
  298.                 DisposeObject(task->iconifygadget);
  299.                 task->iconifygadget=NULL;
  300.             }
  301.  
  302.             if(task->closeguifunc)
  303.                 egCallHook(task->closeguifunc, task->eg_UserData);
  304.  
  305.             task->iconifygadget=NULL;
  306.             task->window=NULL;
  307.             if(    ISBITSET(task->eg->flags, EG_ICONIFIED) |
  308.                     ISBITSET(task->eg->flags, EG_RESET))
  309.                 task->status=STATUS_RESET;
  310.             else
  311.                 task->status=STATUS_CLOSED;
  312.  
  313.             if(task->VisualInfo)
  314.                 FreeVisualInfo(task->VisualInfo);
  315.             if(task->dri)
  316.                 FreeScreenDrawInfo(task->screen, task->dri);
  317.         }
  318.     }
  319. }
  320.  
  321. __asm __saveds void egOpenAllTasks(register __a0 struct EasyGadgets    *eg)
  322. {
  323.     register struct egTask *task;
  324.  
  325.     for(task=eg->tasklist; task; task=task->nexttask)
  326.         if(task->status>STATUS_CLOSED && task->openfunc)
  327.             egCallHook(task->openfunc, (APTR)eg->tasklist);
  328.  
  329.     if(ISBITSET(eg->flags, EG_OPENHELPDOCUMENT))
  330.     {
  331.         egShowAmigaGuide(eg, eg->GuideMsg);
  332.         CLEARBIT(eg->flags, EG_OPENHELPDOCUMENT);
  333.     }
  334. }
  335.  
  336. __asm __inline void closealltasks(register __a0 struct egTask    *task)
  337. {
  338.     if(task->nexttask!=NULL)
  339.         closealltasks(task->nexttask);
  340.     egCloseTask(task);
  341. }
  342.  
  343. __asm __saveds void egCloseAllTasks(register __a0 struct EasyGadgets    *eg)
  344. {
  345.     if(eg->AG_Context)
  346.     {
  347.         CloseAmigaGuide(eg->AG_Context);
  348.         eg->AG_Context=NULL;
  349. //        SETBIT(eg->flags, EG_OPENHELPDOCUMENT);
  350.     }
  351.     closealltasks(eg->tasklist);
  352. }
  353.  
  354. __asm __saveds void egResetAllTasks(register __a0 struct EasyGadgets *eg)
  355. {
  356.     SETBIT(eg->flags, EG_RESET);
  357.     egCloseAllTasks(eg);
  358.     egOpenAllTasks(eg);
  359.     CLEARBIT(eg->flags, EG_RESET);
  360. }
  361.  
  362. __asm __saveds BYTE egTaskToFront(register __a0 struct egTask *task)
  363. {
  364. #ifdef MYDEBUG_H
  365.     DebugOut("egTaskToFront");
  366. #endif
  367.     if(task->window)
  368.     {
  369.         WindowToFront(task->window);
  370.         ActivateWindow(task->window);
  371.         return TRUE;
  372.     }
  373.     return FALSE;
  374. }
  375.  
  376. __asm __saveds void egLinkTasksA(    register __a1 struct EasyGadgets    *eg,
  377.                                                                     register __a0 struct egTask                **tasks)
  378. {
  379.     register ULONG i=0;
  380.     struct egTask *task=tasks[0];
  381.  
  382. #ifdef MYDEBUG_H
  383.     DebugOut("egLinkTasksA");
  384. #endif
  385.  
  386.     eg->tasklist=task;
  387.     while(task!=NULL)
  388.     {
  389.         SETBIT(task->flags, TASK_NOSIZE);
  390.         task->eg                        =eg;
  391.         task->screen                =NULL;
  392.         task->status                =STATUS_CLOSED;
  393.         task->window                =NULL;
  394.         task->iconifygadget    =NULL;
  395.  
  396.         task->nexttask=tasks[++i];
  397.         task                    =tasks[i];
  398.     }
  399. }
  400.  
  401. #endif
  402.